

package com.servlets;

import com.domain.Movies;
import com.domain.service.MoviesService;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HindiMoviesListServlet extends HttpServlet {
   

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

         MoviesService moviesService = new MoviesService();

        List<Movies> moviesList = moviesService.getAll();

        List<Movies> hindiMovies = new ArrayList<Movies>();

        for(int i=0 ;i<moviesList.size();i++){

            if(moviesList.get(i).getLanguage() != null && moviesList.get(i).getLanguage().equalsIgnoreCase("hindi")){
                  hindiMovies.add(moviesList.get(i));
            }
        }

        Collections.sort(hindiMovies);

        PrintWriter out = null;

        try {

            response.setContentType("text/html");

            out = response.getWriter();

            out.println("<html>");
            out.println("<title>AbhiApp | Hindi Movies List</title>");
            out.println("<head></head>");
            out.println("<body>");
            out.println("<h1 align='center'>Hindi Movies</h1><hr/><br>");
            out.println("<table bgcolor='white'align='center' cellspacing='2' cellpadding='10'>");
            out.println("<th>Number                    </th><th>Movie Name</th>");

            int count = 1;
            for (int i = 0; i < hindiMovies.size(); i++) {

                out.println("<tr><td>" + count + "</td>");
                out.println("<td>" + hindiMovies.get(i).getMovieName() + "</td></tr>");

                count++;
            }

            out.println("</table>");
            out.println("<p align='center'><a  href='index.html'>| HOME |</a><a  href='createNewMovie.html'>| CREATE A NEW MOVIE |</a><a  href='MoviesListServlet'>| View All movies |</a></p>");
            out.println("</body>");
            out.println("</html>");

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (out != null) {
                out.close();
            }
        }
    }

     

 
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
     
    }

   

}
